﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "GmStructure.h"
#include "IParameterOverride.h"
#include "IParameterValidator.h"
#include "NdbObjectSchematic.h"
#include "DbDataSchema.h"
#include "UniIdentity.h"



namespace gcmp
{
    class StructWallBuiltInParameterOverrideBase : public IParameterOverride
    {
        DEFINE_CAST_DERIVED(StructWallBuiltInParameterOverrideBase, gcmp::IParameterOverride)
    public:
        virtual UniIdentity GetUniIdentity() const override { return UniIdentity::InvalidUid; }
        virtual bool ShouldOverrideIsModifiable() const override { return false; }
        virtual bool IsModifiable() const override { return true;}

        virtual bool ShouldOverrideIsUserVisible() const override { return false; }
        virtual bool IsUserVisible() const override{ return true;}

        virtual bool ShouldOverrideGetName() const override { return false; }
        virtual std::wstring GetName() const override { return L"";}

        virtual bool ShouldOverrideGetValidator() const override { return false; }
        virtual const IParameterValidator* GetValidator() const override { return nullptr;}

        virtual IElement* GetOwnerElement() override { return nullptr; }
        virtual const IElement* GetOwnerElement() const override { return nullptr; }
        virtual bool SetOwnerElement(IElement* pElement) override { return true; }
    };

    /// \brief 结构构件相关参数通用验证器
    ///
    /// 当前只对基本剪力墙和结构柱做了验证，为了测试新的参数验证模块,
    /// 后续请删除该注释，或者若不满足要求请进行重写
    class StructureGeneralParameterValidator : public NdbObjectSchematic, public IParameterValidator
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, StructureGeneralParameterValidator, gcmp::NdbObjectSchematic, 06A8BF66-C984-4DA8-84DB-968CE7EB4E7A, gmstructure, gcmp::IParameterValidator)
        DBOBJECT_DATA_END

    public:
        virtual OwnerPtr<IParameterValidator> Clone() const override;
        virtual bool Validate(const IParameter* pNewParameter, const IElement* pElement, std::wstring* pErrorMessage = nullptr) const override;

    public: //实现NdbObject接口
        virtual NdbObject* GetTopOwnerObject() const override
        {
            return nullptr;
        }

    private:
        bool ValidateLevel(double associatedLevel, double topAssociatedLevel, double bottomOffset, double topOffset, std::wstring* pErrorMessage) const;
        bool ValidateOffset(double associatedLevel, double topAssociatedLevel, double bottomOffset, double topOffset, std::wstring* pErrorMessage, bool isBottomOffset = false) const;
        bool ValidateHeight(double heightVal, std::wstring* pErrorMessage) const;
    };



    class ParameterValidatorCustomizedOverride : public NdbObjectSchematic, public StructWallBuiltInParameterOverrideBase
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, ParameterValidatorCustomizedOverride, gcmp::NdbObjectSchematic, 9DF3FA7F - 07B2 - 4D73 - 85F0 - 3C812404AE60, gmstructure, gcmp::IParameterOverride)
            DATA(UniIdentity, ParameterUid)
        DBOBJECT_DATA_END

    public:
        ParameterValidatorCustomizedOverride(UniIdentity parameterUid);
        virtual UniIdentity GetUniIdentity() const override;

        virtual bool ShouldOverrideGetValidator() const override;
        virtual const IParameterValidator * GetValidator() const override;

    public: //实现NdbObject接口
        virtual NdbObject* GetTopOwnerObject() const override
        {
            return nullptr;
        }
    };


    class GeneralHeightBuiltInParameterOverride : public NdbObjectSchematic, public StructWallBuiltInParameterOverrideBase
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, GeneralHeightBuiltInParameterOverride, gcmp::NdbObjectSchematic, CAF70268 - D277 - 40FC - B653 - 7A23F9BAC26B, gmstructure, gcmp::StructWallBuiltInParameterOverrideBase)
            DATA(UniIdentity, ParameterUid)
            DATA_TRANSIENT(IElement*, OwnerElement)
        DBOBJECT_DATA_END
    public:
        GeneralHeightBuiltInParameterOverride(IElement* pElement, UniIdentity parameterUid);
        virtual UniIdentity GetUniIdentity() const override;
        virtual bool ShouldOverrideIsModifiable() const override;
        virtual bool IsModifiable() const override;
        virtual IElement* GetOwnerElement() override;
        virtual const IElement* GetOwnerElement() const override;
        virtual bool SetOwnerElement(IElement* pElement) override;

    public: //实现NdbObject接口
        virtual NdbObject* GetTopOwnerObject() const override
        {
            return nullptr;
        }
    };

}
